<template>
  <div>
    <vuedraggable>
      <transition-group>
<!--        <div v-for="item in list" :key="item" class="item">-->
<!--          <p class="add">{{item}}</p>-->
<!--        </div>-->
        <ul v-for="(item,index) in list" :key="index">
          <li >
            <div class="item">{{item.name}}-{{item.address}}</div>
            <button @click="sorting(item,index)">置顶</button>
            //
          </li>
        </ul>
      </transition-group>
    </vuedraggable>
  </div>
</template>

<script>
import vuedraggable from "vuedraggable"
import axios from 'axios'
export default {
  name: 'HelloWorld',
  components:{vuedraggable},
  data(){
    return {
      list:[]
    }
  },
  methods:{
    sorting(item,index){
        this.list.splice(index,1);
        this.list.unshift(item);
    }
  },
  async mounted(){
    const {data} = await axios.get('http://localhost:3000/user')
    this.list = data.record
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
  margin: 40px 0 0;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
.item {
  width:200px;
  height:50px;
  line-height:50px;
  background-color:pink;
}
</style>
